package ssm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import ssm.dao.MyResult;
import ssm.dao.Teacher;
import ssm.dao.Track;
import ssm.dao.TrackCar;
import ssm.model.TeacherMapper;
import ssm.model.TrackCarMapper;
import ssm.service.CarService;
import ssm.service.PersonService;
import ssm.service.StudentService;
import ssm.service.TeacherService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private PersonService personService;
    @Autowired
    private CarService carService;
    @Autowired
    private TrackCarMapper trackCarMapper;


    @RequestMapping("/getPersonInfo")
    @ResponseBody
    public MyResult getPersonInfo(@RequestParam String name){
        Object result=personService.find(name);
        return MyResult.ok(result);
    }

    @RequestMapping("/getCarInfo")
    @ResponseBody
    public MyResult getCarInfo(@RequestParam String cph){
        Object result=carService.find(cph);
        return MyResult.ok(result);
    }


    @RequestMapping("/SearchCar")
    @ResponseBody
    public MyResult searchCar(@RequestParam String cph){
        TrackCar trackCar=trackCarMapper.searchCar(cph);
        return MyResult.ok(trackCar);
    }

    //todo
    @RequestMapping("/SearchTeacherByCph")
    @ResponseBody
    public MyResult SearchTeacherByCph(String cph){
        Teacher teacher=personService.SearchTeacherByCph(cph);
        return MyResult.ok(teacher);
    }
}
